//
//  HSYShopInfo.m
//  HSY
//
//  Created by 陈浩 on 2017/4/5.
//  Copyright © 2017年 金开门. All rights reserved.
//

#import "HSYShopInfo.h"

static HSYShopInfo *currentShop = nil;

@implementation HSYShopInfo

+ (instancetype)sharedShopInfo {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        currentShop = [[self alloc] init];;
    });
    
    return currentShop;
}

+(id)allocWithZone:(struct _NSZone *)zone
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        currentShop = [super allocWithZone:zone];
    });
    
    return currentShop;
}

#if !__has_feature(objc_arc)

-(id)mutableCopyWithZone:(NSZone *)zone
{
    return currentUserZone;
}

-(id)copyWithZone:(NSZone *)zone
{
    return currentUserZone;
}

#endif


#pragma mark - MJExtension -
+(NSDictionary *)replacedKeyFromPropertyName{
    return @{@"shopID" : @"id"};
}

#pragma mark -AutoCoding 自动进行归档
static inline NSString * ShopInfoSaveFile(){
    return [NSHomeDirectory() stringByAppendingString:@"/Documents/HSYShopInfo"];
}

+ (void)restoreShopInfo {
    NSString *path = ShopInfoSaveFile();
    // 从path路径找到并解档案
    [self objectWithContentsOfFile:path];
}
+ (void)saveShopInfoToDocuments{
    NSString *path = ShopInfoSaveFile();
    HSYShopInfo *shopInfo = [HSYShopInfo sharedShopInfo];
    [shopInfo writeToFile:path atomically:YES];
}

+ (void)removeSaveShopInfo{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isHave = [fileManager fileExistsAtPath:ShopInfoSaveFile()];
    if (isHave) {
        [fileManager removeItemAtPath:ShopInfoSaveFile() error:nil];
    }
    
    [HSYShopInfo sharedShopInfo].shopID = nil;
    [HSYShopInfo sharedShopInfo].shortName = nil;
    [HSYShopInfo sharedShopInfo].industryCode = nil;
    [HSYShopInfo sharedShopInfo].districtCode = nil;
    [HSYShopInfo sharedShopInfo].licenceID = nil;
    [HSYShopInfo sharedShopInfo].storefrontID = nil;
    [HSYShopInfo sharedShopInfo].counterID = nil;
    [HSYShopInfo sharedShopInfo].indoorID = nil;
    [HSYShopInfo sharedShopInfo].parentID = nil;
    [HSYShopInfo sharedShopInfo].contactName = nil;
    [HSYShopInfo sharedShopInfo].contactCellphone = nil;
    [HSYShopInfo sharedShopInfo].status = nil;
    [HSYShopInfo sharedShopInfo].isPublic = 0;
    [HSYShopInfo sharedShopInfo].createTime = 0;
    [HSYShopInfo sharedShopInfo].updateTime = 0;
}

@end
